// https://router.vuejs.org/zh/
import { RouteRecordRaw, createRouter, createWebHistory } from 'vue-router'
import { i18n } from '@/lang/index';
// 定义路由，每个路由都需要映射到一个组件
const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: "/home"
  },
  {
    path: '/home',
    name: "home",
    meta: { index: 0, title: i18n.global.t('menu1') },
    component: () => import('@/views/home/index.vue'),
  },
  {
    path: '/nft',
    name: "nft",
    meta: { index: 0, title: i18n.global.t('menu2') },
    component: () => import('@/views/nft/index.vue'),
  },
  {
    path: '/wallet',
    name: "wallet",
    meta: { index: 0, title: i18n.global.t('menu3') },
    component: () => import('@/views/wallet/index.vue'),
  },
  {
    path: '/walletRecord',
    name: "walletRecord",
    meta: { index: 0, title: i18n.global.t('menu3') },
    component: () => import('@/views/wallet/walletRecord.vue'),
  },
  {
    path: '/walletDetails',
    name: "walletDetails",
    meta: { index: 0, title: i18n.global.t('withdrawalsRecord') },
    component: () => import('@/views/wallet/walletDetails.vue'),
  },
  {
    path: '/community',
    name: "community",
    meta: { index: 0, title: i18n.global.t('menu4') },
    component: () => import('@/views/community/index.vue'),
  },
  {
    path: '/invite',
    name: 'invite',
    meta: { index: 0, title: i18n.global.t('menu5') },
    component: () => import('@/views/invite/index.vue'),
  },
  {
    path: '/inviteList',
    name: 'inviteList',
    meta: { index: 0, title: i18n.global.t('menu5') },
    component: () => import('@/views/invite/list.vue'),
  },
  {
    path: '/ecology',
    name: 'ecology',
    meta: { index: 0, title: i18n.global.t('menu6') },
    component: () => import('@/views/ecology/index.vue'),
  },
  {
    path: '/rank',
    name: 'rank',
    meta: { index: 0, title: i18n.global.t('menu7') },
    component: () => import('@/views/rank/index.vue'),
  },
  {
    path: '/welfare',
    name: 'welfare',
    meta: { index: 0, title: i18n.global.t('menu8') },
    component: () => import('@/views/welfare/index.vue'),
  },
  {
    path: '/node',
    name: 'node',
    meta: { index: 0, title: i18n.global.t('menu9') },
    component: () => import('@/views/node/index.vue'),
  },
  {
    path: '/about',
    name: 'about',
    meta: { index: 0, title: i18n.global.t('faqTitle') },
    component: () => import('@/views/about/index.vue'),
  },
  {
    path: '/game',
    name: 'game',
    meta: { index: 0, title: i18n.global.t('menu11') },
    component: () => import('@/views/game/index.vue'),
  },
  { path: "/:pathMatch(.*)", redirect: "/" }
]

// 创建路由实例并传递 `routes` 配置
console.log(routes, "routes")
const router = createRouter({
  history: createWebHistory(process.env.VUE_APP_PUBLIC_PATH),
  // history: createWebHashHistory('/'),
  routes,
  scrollBehavior() {
    // 始终滚动到顶部
    return { top: 0 }
  },
})

router.beforeEach((_to: any, _from, next) => {
  document.title = _to.meta.title || 'Your Default Title'
  next()
})


// 导出路由实例，并在 `main.ts` 挂载
export default router
